package com.linshengjian.snowball.core.controller;

import com.linshengjian.snowball.core.BaseModel;
import com.linshengjian.snowball.core.IWriteService;
import com.linshengjian.snowball.core.exception.BusinessException;
import com.linshengjian.snowball.core.exception.SystemErrorException;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;

import java.io.Serializable;

public class BaseWriteController<ID extends Serializable,M extends BaseModel<ID>, S extends IWriteService<M, ID>> {

    @Autowired
    private S service;

    @ApiOperation("新增")
    @PostMapping
    public M add(M model) throws SystemErrorException, BusinessException {
        return service.add(model);
    }

    @ApiOperation("修改")
    @PutMapping
    public M update(M model) throws SystemErrorException, BusinessException {
        return service.update(model);
    }

    @ApiOperation("删除")
    @DeleteMapping("{id}")
    public void delete(@PathVariable ID id) throws BusinessException, SystemErrorException {
        service.delete(id);
    }

}
